from functools import wraps

from flask import session, current_app, g




def news_class_filter(index):
    if index == 1:
        return "first"
    elif index == 2:
        return "second"
    elif index == 3:
        return "third"
    else:
        ""


def user_login_data(func):
    @wraps(func)
    def call_fun(*args, **kwargs):
        user_id = session.get('user_id')
        from info.models import User
        user = None
        if user_id:
            try:
                # user = User.query.filter(User.id == user_id).first()
                user = User.query.get(user_id)
            except Exception as e:
                current_app.logger.error(e)
        g.user = user
        return func(*args, **kwargs)

    return call_fun
